package com.github.lee.unsplash.manager

import android.content.SharedPreferences
import androidx.lifecycle.MutableLiveData
import com.github.lee.unsplash.domain.AuthBean
import javax.inject.Inject

private const val KEY_TOKEN = "TOKEN"

class LoginManager @Inject constructor(private val sp: SharedPreferences) {
    companion object {
        val loginSuccessLiveData = MutableLiveData<Boolean>()
    }

    var authBean: AuthBean? = null

    val isLogin: Boolean
        get() = accountToken.isNotEmpty()

    val accountToken: String
        get() {
            return sp.getString(KEY_TOKEN, "") ?: ""
        }

    //===Desc:=========================================================
    fun login(authBean: AuthBean) {
        sp.edit()
            .putString(KEY_TOKEN, authBean.accessToken)
            .apply()
    }

}